<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/3
 * Time: 8:51
 */

class MyUtil
{


    /**
     * 上传图片
     * **/
    public function upload_fengcai_pp() {
        $this->_Admin_checkUser();//后台权限检测
        $upload_path = $this->get('upload_path');
        if(!empty($_FILES)) {
            //如果有文件上传 上传附件
            $this->_upload_fengcai_pp($upload_path);
        }
    }

    protected function _upload_fengcai_pp($upload_path='shop')
    {
        header("content-type:text/html;charset=utf-8");
        $this->_Admin_checkUser();//后台权限检测
        // 文件上传处理函数

        //载入文件上传类
        import("@.ORG.UploadFile");
        $upload = new UploadFile();

        //设置上传文件大小
        $upload->maxSize  = 1048576 * 2 ;// TODO 50M   3M 3292200 1M 1048576

        //设置上传文件类型
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg,mp3');

        //设置附件上传目录
        $upload->savePath =  './Public/Uploads/image/' .$upload_path . '/';

        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb =  false;

        //设置需要生成缩略图的文件前缀
        $upload->thumbPrefix   =  'm_';  //生产2张缩略图

        //设置缩略图最大宽度
        $upload->thumbMaxWidth =  '800';

        //设置缩略图最大高度
        $upload->thumbMaxHeight = '600';

        //设置上传文件规则
//		$upload->saveRule = uniqid;
        $upload->saveRule = date("Y").date("m").date("d").date("H").date("i").date("s").rand(1,100);

        //删除原图
        $upload->thumbRemoveOrigin = true;

        if(!$upload->upload()) {
            //捕获上传异常
            $error_p=$upload->getErrorMsg();
            echo "<script>alert('".$error_p."');history.back();</script>";
        }else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            $U_path=$uploadList[0]['savepath'];
            $U_nname=$uploadList[0]['savename'];
            $U_inpath=(str_replace('./Public/','__PUBLIC__/',$U_path)).$U_nname;
             //return $this->ajaxReturn({"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": '.$id.'}}});
            echo "<script>window.parent.form1.image.value='".$U_inpath."';</script>";
             echo "<span style='font-size:12px;'>上传完成！</span>";
            exit;

        }
    }
}